<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Library Evolutionary Algorithms for Clustering (LEAC): include/leac_utils.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="leac_logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Library Evolutionary Algorithms for Clustering (LEAC)
   &#160;<span id="projectnumber">Version 1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">leac_utils.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="leac__utils_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#ifndef __LEAC_UTILS_HPP</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#define __LEAC_UTILS_HPP</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &lt;utility&gt;</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &lt;typeinfo&gt;</span>    <span class="comment">// operator typeid</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#include &lt;type_traits&gt;</span> <span class="comment">//std::common_type</span></div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#include &lt;cmath&gt;</span>       <span class="comment">//std::isless</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &lt;cassert&gt;</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceutils.html">utils</a> {</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;</div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="leac__utils_8hpp.html#a02440753741b9682fc19a2354a347553">   31</a></span>&#160;<span class="preprocessor">#define assert_msg(x) !(std::cerr &lt;&lt; &quot;Assertion failed: &quot; &lt;&lt; x &lt;&lt; std::endl)</span></div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="structutils_1_1_instance_data_type.html">   36</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structutils_1_1_instance_data_type.html">InstanceDataType</a></div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;{</div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="structutils_1_1_instance_data_type.html#af34d1b4c99de2926d8c631e66606222a">   38</a></span>&#160;  <span class="keywordtype">long</span>   <a class="code" href="structutils_1_1_instance_data_type.html#af34d1b4c99de2926d8c631e66606222a">sum</a>(<span class="keywordtype">int</span>)<span class="keyword">    const </span>{ <span class="keywordflow">return</span> long(1); }</div><div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="structutils_1_1_instance_data_type.html#a2c0f67a7d0d2ec760b3982bb34a1d00a">   39</a></span>&#160;  <span class="keywordtype">double</span> <a class="code" href="structutils_1_1_instance_data_type.html#a2c0f67a7d0d2ec760b3982bb34a1d00a">sum</a>(<span class="keywordtype">double</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> double(1); }</div><div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="structutils_1_1_instance_data_type.html#a6bec8d3de9ff7058111adf328696169e">   40</a></span>&#160;  <span class="keywordtype">float</span>  <a class="code" href="structutils_1_1_instance_data_type.html#a6bec8d3de9ff7058111adf328696169e">sum</a>(<span class="keywordtype">float</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> float(1); }</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;</div><div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="structutils_1_1_instance_data_type.html#a7ef764f471c5476d76a7d56ab23059f5">   42</a></span>&#160;  <span class="keywordtype">long</span>   <a class="code" href="structutils_1_1_instance_data_type.html#a7ef764f471c5476d76a7d56ab23059f5">sumFrequency</a>(<span class="keywordtype">int</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> long(1); }</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;  </div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;};</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="structutils_1_1_run_once.html">   49</a></span>&#160;<span class="keyword">struct </span><a class="code" href="structutils_1_1_run_once.html">RunOnce</a> {</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;  <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="structutils_1_1_run_once.html#abc7ff93107c758b0a2548946b45fcab4">   51</a></span>&#160;  <a class="code" href="structutils_1_1_run_once.html#abc7ff93107c758b0a2548946b45fcab4">RunOnce</a>(T &amp;&amp;<a class="code" href="namespaceinout.html#a5321a07527d7e234b9cdc037bda4ab86">f</a>) { <a class="code" href="namespaceinout.html#a5321a07527d7e234b9cdc037bda4ab86">f</a>(); }</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;};</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="keyword">template</span>&lt; <span class="keyword">typename</span> A, <span class="keyword">typename</span> B &gt;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="keyword">inline</span></div><div class="line"><a name="l00063"></a><span class="lineno"><a class="line" href="namespaceutils.html#a78043969e145eda76b0123263d782fb9">   63</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="namespaceutils.html#a78043969e145eda76b0123263d782fb9">closeenough</a>(A <span class="keyword">const</span> &amp; <a class="code" href="namespaceinout.html#a34622d1ba64f6d5ec4135002a95dcf5b">a</a>, B <span class="keyword">const</span> &amp; b,</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;                  <span class="keyword">typename</span> std::common_type&lt; A, B &gt;::type <span class="keyword">const</span> &amp; epsilon)</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;{</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  <span class="comment">//using std::isless;</span></div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  assert(std::isless(0, epsilon)); <span class="comment">// epsilon is a part of the whole quantity</span></div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  assert(std::isless(epsilon, 1));</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  <span class="comment">//using std::abs;</span></div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;  <span class="keyword">auto</span> <span class="keyword">const</span> delta = std::abs(<a class="code" href="namespaceinout.html#a34622d1ba64f6d5ec4135002a95dcf5b">a</a> - b);</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;  <span class="keyword">auto</span> <span class="keyword">const</span> x = std::abs(<a class="code" href="namespaceinout.html#a34622d1ba64f6d5ec4135002a95dcf5b">a</a>);</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;  <span class="keyword">auto</span> <span class="keyword">const</span> y = std::abs(b);</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;  </div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;  <span class="comment">// comparable generally and |a - b| &lt; eps * (|a| + |b|) / 2</span></div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  <span class="keywordflow">return</span> std::isless(epsilon * y, x) &amp;&amp;</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    std::isless(epsilon * x, y) &amp;&amp;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    std::isless((delta + delta) / (x + y), epsilon);</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;}</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  </div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;} <span class="comment">/*END namespace utils </span></div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="comment">   */</span></div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/*__LEAC_UTILS_HPP*/</span><span class="preprocessor"></span></div><div class="ttc" id="namespaceutils_html_a78043969e145eda76b0123263d782fb9"><div class="ttname"><a href="namespaceutils.html#a78043969e145eda76b0123263d782fb9">utils::closeenough</a></div><div class="ttdeci">bool closeenough(A const &amp;a, B const &amp;b, typename std::common_type&lt; A, B &gt;::type const &amp;epsilon)</div><div class="ttdoc">Check if two real numbers are close enough or equal.</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00063">leac_utils.hpp:63</a></div></div>
<div class="ttc" id="structutils_1_1_instance_data_type_html_a2c0f67a7d0d2ec760b3982bb34a1d00a"><div class="ttname"><a href="structutils_1_1_instance_data_type.html#a2c0f67a7d0d2ec760b3982bb34a1d00a">utils::InstanceDataType::sum</a></div><div class="ttdeci">double sum(double) const</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00039">leac_utils.hpp:39</a></div></div>
<div class="ttc" id="structutils_1_1_instance_data_type_html_a7ef764f471c5476d76a7d56ab23059f5"><div class="ttname"><a href="structutils_1_1_instance_data_type.html#a7ef764f471c5476d76a7d56ab23059f5">utils::InstanceDataType::sumFrequency</a></div><div class="ttdeci">long sumFrequency(int) const</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00042">leac_utils.hpp:42</a></div></div>
<div class="ttc" id="structutils_1_1_instance_data_type_html"><div class="ttname"><a href="structutils_1_1_instance_data_type.html">utils::InstanceDataType</a></div><div class="ttdoc">Structure For a data type of an attribute of an instance, it defines the data type recommended for th...</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00036">leac_utils.hpp:36</a></div></div>
<div class="ttc" id="structutils_1_1_run_once_html"><div class="ttname"><a href="structutils_1_1_run_once.html">utils::RunOnce</a></div><div class="ttdoc">Structure to ensure that a code or function is executed only once.</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00049">leac_utils.hpp:49</a></div></div>
<div class="ttc" id="structutils_1_1_instance_data_type_html_a6bec8d3de9ff7058111adf328696169e"><div class="ttname"><a href="structutils_1_1_instance_data_type.html#a6bec8d3de9ff7058111adf328696169e">utils::InstanceDataType::sum</a></div><div class="ttdeci">float sum(float) const</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00040">leac_utils.hpp:40</a></div></div>
<div class="ttc" id="namespaceinout_html_a34622d1ba64f6d5ec4135002a95dcf5b"><div class="ttname"><a href="namespaceinout.html#a34622d1ba64f6d5ec4135002a95dcf5b">inout::a</a></div><div class="ttdeci">case a</div><div class="ttdef"><b>Definition:</b> <a href="inparamclustering__getparameter_8hpp_source.html#l04548">inparamclustering_getparameter.hpp:4548</a></div></div>
<div class="ttc" id="structutils_1_1_instance_data_type_html_af34d1b4c99de2926d8c631e66606222a"><div class="ttname"><a href="structutils_1_1_instance_data_type.html#af34d1b4c99de2926d8c631e66606222a">utils::InstanceDataType::sum</a></div><div class="ttdeci">long sum(int) const</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00038">leac_utils.hpp:38</a></div></div>
<div class="ttc" id="namespaceinout_html_a5321a07527d7e234b9cdc037bda4ab86"><div class="ttname"><a href="namespaceinout.html#a5321a07527d7e234b9cdc037bda4ab86">inout::f</a></div><div class="ttdeci">case f</div><div class="ttdef"><b>Definition:</b> <a href="inparamclustering__getparameter_8hpp_source.html#l04573">inparamclustering_getparameter.hpp:4573</a></div></div>
<div class="ttc" id="structutils_1_1_run_once_html_abc7ff93107c758b0a2548946b45fcab4"><div class="ttname"><a href="structutils_1_1_run_once.html#abc7ff93107c758b0a2548946b45fcab4">utils::RunOnce::RunOnce</a></div><div class="ttdeci">RunOnce(T &amp;&amp;f)</div><div class="ttdef"><b>Definition:</b> <a href="leac__utils_8hpp_source.html#l00051">leac_utils.hpp:51</a></div></div>
<div class="ttc" id="namespaceutils_html"><div class="ttname"><a href="namespaceutils.html">utils</a></div><div class="ttdoc">General Purpose Utilities.</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 19 2019 08:58:31 for Library Evolutionary Algorithms for Clustering (LEAC) by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.15
</small></address>
</body>
</html>
